function verifyEmail(email)
{
	if(email!=""){
		data = email.match(/^\S+@\S+\.\S+$/);
		if (!data) {
			return false;
		}
	}
		return true;
}


if (window.location.protocol == "http:") {
    var restOfUrl = window.location.href.substr(5);
    //window.location = "https:" + restOfUrl;
}

function showErrorMessageDialog(message)
{
    $('#messageDiv').dialog('destroy');
    $('#messageDiv').show();
    $('#messageDiv').html(message);
    
    $("#messageDiv" ).dialog({
    	title:'<span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span><strong>錯誤訊息</strong>' 
        , width: 300
        , resizable: false
        , modal: true        
        , overlay: {
            backgroundColor: '#000',
            opacity: 0.9
        }
        , buttons: {
            Ok: function() {
                $( this ).dialog( "close" );
            }
        }
    }).prev().addClass('ui-state-error');
}

function showMessageDialog(message, strtitle)
{
	if(!strtitle) strtitle='訊息';
    $('#messageDiv').dialog('destroy');
    $('#messageDiv').show();
    $('#messageDiv').html(message);
    
    $("#messageDiv" ).dialog({
    	title:'<span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span><strong>'+strtitle+'</strong>' 
        , width: 300
        , resizable: false
        , modal: true        
        , overlay: {
            backgroundColor: '#000',
            opacity: 0.9
        }
        , buttons: {
            Ok: function() {
                $( this ).dialog( "close" );
            }
        }
    }).prev().addClass('ui-state-highlight');
}

function divPrint(divId)
{
	var content_vlue = document.getElementById(divId).innerHTML;
	
	if (null == content_vlue || content_vlue.length == 0)
		return;
	
	var width  = 800;
	var height = 600;
	if (window.screen) {
		width = window.screen.availWidth;
		height = window.screen.availHeight;
	}
	
	var left   = (screen.width  - width)/2;
	var top    = (screen.height - height)/2;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=no';
	params += ', scrollbars=yes';
	params += ', status=no';
	params += ', toolbar=yes';
	params += ', fullscreen=no';
	
	
	var docprint=window.open("","", params);
	docprint.document.open();
	docprint.document.write('<html><head><title>遠銀網銀股票交割款扣撥系統</title>');
	docprint.document.write('<link rel="stylesheet" type="text/css" media="all" href="styles/default/mainstyle.css"/>');
	docprint.document.write('<link rel="stylesheet" type="text/css" media="all" href="styles/default/jquery-ui-1.8.20.custom.css"/>');
	docprint.document.write('</head><body onLoad="window.print();"><center><div id="wrapper"><div id="container"><div id="mainForm"><div id="listForm">');
	docprint.document.write(content_vlue);
	docprint.document.write('</div></div></div></div></center></body></html>');
	docprint.document.close();
	docprint.focus(); 
}

jQuery.download = function(url, data, method){
		//url and data options required
		if( url && data ){
			//data can be string of parameters or array/object
			data = typeof data == 'string' ? data : jQuery.param(data);
			//split params into form inputs
			//send request
			if (null == $('#myDLIFrm')){
				jQuery('<iframe id="myIFrm" src="' + url + '?'+ data +'" style="display:none; visibility: hidden;"></iframe>').appendTo('body');
			}
			else {
				$('#myDLIFrm').attr("src", url + '?'+ data );
			}
			
			
		};
	};
	
function ExportToExcel(url, data, event) {

	if( url && data && event)
	{
		waitingDialog({});
		
		//data can be string of parameters or array/object
		data = typeof data == 'string' ? data : jQuery.param(data);
		
		if($.browser.msie)
		//if (true)
		{
			// 啟動匯出檔案，關閉loading(For IE) 
			var inputs = "";
			$.each(data.split('&'), function () { 
	            var pair = this.split('='); 
	            inputs += "<input type='hidden' name='" + pair[0] + "' value='" + pair[1] + "' />"; 
	        });
	        
	        inputs += "<input type='hidden' name='" + event + "' value='" + event + "' />"; 
	        	        
	        var iframe = document.createElement("iframe");
	        iframe.style.visibility = 'hidden';
	        iframe.style.display = 'none';
	        document.body.appendChild(iframe); 
	        
	        var frame = iframe.contentWindow.document; 
	        frame.writeln("<form id='form1' action='"+url+"' method='post'>" + inputs + "</form>");
	        
	        frame.getElementById("form1").submit(); 
	        $(frame).one("readystatechange", function ()
	        {
	        	if (document.readyState == "complete") {
	        		closeWaitingDialog();
	        	} 
	        });
	        
		}
		else if($.browser.mozilla)
		{
			// 啟動匯出檔案，關閉loading(For F) 
			
			
	        var iframe = document.createElement("iframe"); 
	        iframe.style.visibility = 'hidden';
	        iframe.style.display = 'none';
	        
	        iframe.src = url + '?' + event + '=' + event + '&' + data ;
	        	        
	        document.body.appendChild(iframe); 
	        
	        if (iframe.attachEvent) {
	        	iframe.attachEvent("onload", function () {
	        		closeWaitingDialog(); 
	        	}); 
	        } 
	        else 
	        {
	        	iframe.onload = function () { 
	        		closeWaitingDialog();
	        	}; 
	        } 
		}
	}
 }